package org.batatasframework.web.element;

import org.batatasframework.web.HtmlRenderHelper;

public class TableTd extends AbstractElementContent<Object> implements Comparable<TableTd>{
	
	public final static TableTd SKIP = new TableTd(null){
		public String toString() { return ""; }
	};
	
	private int colspan;
	private int rowspan;
	
	private int ordinal;
	
	@Override
	public int compareTo(TableTd o) {
		return ordinal = o.ordinal;
	}
	
	public void setOrdinal(int ordinal) {
		this.ordinal = ordinal;
	}
	
	private TableTd(String name){
		super(name);
	}
	
	public static TableTd td(){
		return new TableTd("td");
	}
	
	public static TableTd th(){
		return new TableTd("th");
	}
	
	public int getColspan() {
		return colspan;
	}

	public void setColspan(int colspan) {
		this.colspan = colspan;
	}

	public int getRowspan() {
		return rowspan;
	}

	public void setRowspan(int rowspan) {
		this.rowspan = rowspan;
	}

	@Override
	protected void readAttribute(StringBuilder html) {
		if(colspan > 1){
			HtmlRenderHelper.attribute(html, "colspan", colspan, false);
		}
		if(rowspan > 1){
			HtmlRenderHelper.attribute(html, "rowspan", rowspan, false);
		}
		super.readAttribute(html);
	}
}
